from symbide import LogManager
from widgetOrganizer import WidgetOrganizer
import gtk

class StatusBar(WidgetOrganizer, gtk.VBox):
    def __init__(self, ancestor):
        gtk.VBox.__init__(self)
        WidgetOrganizer.__init__(self, 'StatusBar', ancestor)
        
        separator = gtk.HSeparator()
        separator.show()
        self.pack_start(separator, expand=False)
        
        self.hbox = gtk.HBox()
        self.hbox.show()
        self.pack_start(self.hbox, expand=False)
        
        self._createDisplay()
        LogManager.setOutput(self.write)
        LogManager('Starting')
        
    def _createDisplay(self):        
        self.label = gtk.Label('')
        self.label.show()
        self.hbox.pack_start(self.label, expand=False, padding=10)
        
        
    def write(self, text):
        if text.startswith('<alert>') and text.endswith('</alert>'):
            alert = True
            text = text[7:-8]
        else:
            alert = False
            
        if len(text)>80:
            text = text[:77]+'...'
            
        if alert:
            text = '<span foreground="#ff0000">%s</span>'%text
        self.label.set_text(text)
        self.label.set_use_markup(True)